﻿using System;

using ApplicationLibrary;
using ApplicationLibrary.SqlConnector;

namespace Vintner.Sales.ModuleData
{
    internal class RegisterModule : ApplicationLibrary.SqlConnector.RegisterModule
    {
        public override string Application()
        {
            return "VINT";
        }

        public override string Module()
        {
            return "SALE";
        }

        public override int CurrentVersion()
        {
            return 1;
        }

        public override Version DllVersion
        {
            get
            {
                return System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
            }
        }

        public override void RegisterCountersAndCodes()
        {
            GlobalInfo.AddCounter((int)Counters.SaleInvoice, Properties.Resources.CN_SalesInvoice);
        }

        public override void AddScrounger(ApplicationLibrary.DBManager.iScrounger frm, NameSpace nameSpace)
        {
            //if (nameSpace.ApplicationPath == "Plumber.Plumber.Masters.Forms.Masters")
            //    frm.ScroungerList.Add()
        }

        public override ApplicationLibrary.Preferences.PreferencePanel[] RegisterPreferences()
        {
            //return new ApplicationLibrary.Preferences.PreferencePanel[]
            //{
            //    new AccountingPreferencePanel()
            //};
            return null;
        }

        protected override bool CreateDBTables()
        {
            SqlCreateTable newTable = new SqlCreateTable(SqlABConnection);

            #region VI_SaleInvoices

            if (SearchTable(VI_SaleInvoices.Name))
            {
                newTable.NewTable(VI_SaleInvoices.Name);

                newTable.AddColumn(VI_SaleInvoices.IsDado);
                newTable.AddColumn(VI_SaleInvoices.InvoiceNo);
                newTable.AddColumn(VI_SaleInvoices.ReleaseDate);
                newTable.AddColumn(VI_SaleInvoices.Customer);
                newTable.AddColumn(VI_SaleInvoices.Description);
                newTable.AddColumn(VI_SaleInvoices.Title);
                newTable.AddColumn(VI_SaleInvoices.Address);
                newTable.AddColumn(VI_SaleInvoices.ZipCode);
                newTable.AddColumn(VI_SaleInvoices.City);
                newTable.AddColumn(VI_SaleInvoices.County);
                newTable.AddColumn(VI_SaleInvoices.TaxNo);
                newTable.AddColumn(VI_SaleInvoices.FiscalCode);
                newTable.AddColumn(VI_SaleInvoices.Payment);

                newTable.AddColumn(VI_SaleInvoices.PackagesNo);
                newTable.AddColumn(VI_SaleInvoices.LitresNo);
                newTable.AddColumn(VI_SaleInvoices.Appearance);
                newTable.AddColumn(VI_SaleInvoices.DestGoods);
                newTable.AddColumn(VI_SaleInvoices.Transport);
                newTable.AddColumn(VI_SaleInvoices.TransportDate);

                newTable.AddPrimaryKey(VI_SaleInvoices.IsDado, VI_SaleInvoices.InvoiceNo);
                newTable.Create();
            }

            #endregion

            #region VI_SaleInvoicesDetails

            if (SearchTable(VI_SaleInvoicesDetails.Name))
            {
                newTable.NewTable(VI_SaleInvoicesDetails.Name);

                newTable.AddColumn(VI_SaleInvoicesDetails.IsDado);
                newTable.AddColumn(VI_SaleInvoicesDetails.InvoiceNo);
                newTable.AddColumn(VI_SaleInvoicesDetails.Line);
                newTable.AddColumn(VI_SaleInvoicesDetails.Item);
                newTable.AddColumn(VI_SaleInvoicesDetails.Description);
                newTable.AddColumn(VI_SaleInvoicesDetails.Category);
                newTable.AddColumn(VI_SaleInvoicesDetails.Price);
                newTable.AddColumn(VI_SaleInvoicesDetails.TaxCode);
                newTable.AddColumn(VI_SaleInvoicesDetails.Quantity);
                newTable.AddColumn(VI_SaleInvoicesDetails.Litres);
                newTable.AddColumn(VI_SaleInvoicesDetails.Lot);

                newTable.AddPrimaryKey(VI_SaleInvoices.IsDado, VI_SaleInvoices.InvoiceNo, VI_SaleInvoicesDetails.Line);

                newTable.Create();
            }

            #endregion

            return true;
        }

        protected override bool UpdateDBTables()
        {
            return true;
        }
    }
}